<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author quqiang <quqiang@geek-zoo.com>
 *
 */


require_once ROOT_PATH.'/Abstract/front_abstract.php';

class Action extends front_abstract
{
	function index()
	{
		$id = _GET('id');
		$return = $this->api->statuses_show($this->access_token, $id);
		$return = array('0'=>$return);
		
        $ids = array();

         foreach ($return as $key => $val) {
            $ids[] = $val['id'];
            if (isset($val['retweeted_status'])) {
                $ids[] = $val['retweeted_status']['id'];
            }
         }

         $data = $this->api->counts($this->oauth_token, $this->oauth_token_secret,  array_unique($ids));

         $t = $this->api->emotions($this->access_token);
         $face = array();
         foreach ($t as $key => $val) {
            $face[$val['phrase']] = '<img src="'.$val['url'].'" />';
         }

         foreach ($return as $key => $val) {
            $return[$key]['text'] = strtr($val['text'], $face);
            if (isset($data[$val['id']])) {
                $return[$key]['counts'] = $data[$val['id']];
            } else {
                $return[$key]['counts'] = array(
                    'comments' => 0,
                    'rt' => 0
                );
            }
            if (isset($val['retweeted_status'])) {
                if (isset($data[$val['retweeted_status']['id']])) {
                    $return[$key]['retweeted_status']['counts'] = $data[$val['retweeted_status']['id']];
                } else {
                    $return[$key]['retweeted_status']['counts'] = array(
                        'comments' => 0,
                        'rt' => 0
                    );
                }
                $return[$key]['retweeted_status']['text'] = strtr($val['retweeted_status']['text'], $face);
            }
         }
		// print_r($return);

        $data = $this->api->counts($this->oauth_token, $this->oauth_token_secret,  array_unique($ids));
		$this->smarty->assign('t_data', $return);
		$this->smarty->assign('id', $id);
        $this->smarty->display('lib/statuses_show.html');
	}
}

?>